package com.xinnet.mms.login.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.mms.entity.Dept;
import com.xinnet.mms.entity.Emp;
import com.xinnet.mms.login.dao.EmpDao;

@Repository
public class EmpDaoImpl extends BaseDaoImpl<Emp, Long> implements EmpDao {

	@Override
	public Emp queryEmpByLoginName(String loginName) {
		// TODO Auto-generated method stub
		return super.getSqlSession().selectOne("emp.queryEmpByLoginName", loginName);
	}
	public Emp getEmpListByDeptId(String deptId){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpListByDeptId",deptId);
		if(empList == null || empList.size()<=0){
			return null;
		}
		return empList.get(0);
	}
	
	@Override
	public List<String> getEmpNoList(Emp emp) {
		List<String> empList = super.getSqlSession().selectList("emp.getEmpNoList",emp);
		if(empList!=null && empList.size()==0){
			empList = null;
		}
		return empList;
	}
	public List<Emp> getEmpList(Emp emp){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpList",emp);
		if(empList!=null && empList.size()==0){
			empList = null;
		}
		return empList;
	}
	public void updateEmp(Emp emp){
		super.getSqlSession().update("emp.updateEmp",emp);
	}
	
	public List<Emp> getEmpByLoginName(String loginName){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpByLoginName",loginName);
		if(empList!=null && empList.size()==0){
			empList = null;
		}
		return empList;
	}
	
	public List<Emp> getAllEmpList(){
		List<Emp> empList = super.getSqlSession().selectList("emp.getAllEmpList");
		return empList;
	}
	
	public List<Emp> getEmpListByDeptIdStr(String deptIdStr){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpListByDeptIdStr",deptIdStr);
		return empList;
	}
	public List<Emp> getEmpListByDeptIdStrOrNoDeptRoleId(String deptIdStr){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpListByDeptIdStrOrNoDeptRoleId",deptIdStr);
		return empList;	
	}
	public List<Emp> getEmpSetApprovalListByDeptIdStr(String deptIdStr){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpSetApprovalListByDeptIdStr",deptIdStr);
		return empList;
	}
	public List<Emp> getEmpListExceptDeptLeader(String deptId){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpListExceptDeptLeader",deptId);
		return empList;
	}
	
	public void updateEmpAccount(Emp emp){
		super.getSqlSession().update("emp.updateEmpAccount",emp);
	}
	
	public void updateEmpRole(Emp emp){
		super.getSqlSession().update("emp.updateEmpRole",emp);
	}
	
	public void addEmp(Emp emp){
		super.getSqlSession().insert("emp.addEmp",emp);
	}
	
	public List<Dept> getDeptByParentId(String deptId){
		List<Dept> deptList = super.getSqlSession().selectList("Dept.getDeptByParentId",deptId);
		return deptList;
	}
	
	public List<Emp> getEmpByDeptAndChildDept(String deptId){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpByDeptAndChildDept",deptId);
		if(empList!=null && empList.size()==0){
			empList = null;
		}
		return empList;
	}
	
	public List<Emp> getEmpListForChildDept(String deptId){
		List<Emp> empList = super.getSqlSession().selectList("emp.getEmpListForChildDept",deptId);
		if(empList!=null && empList.size()==0){
			empList = null;
		}
		return empList;
	}
	
	/**根据员工编号获取员工*/
	@Override
	public Emp getEmpbyEmpno(@Param(value="empno") String empno) {
		return this.getSqlSession().selectOne("emp.getEmpbyEmpno",empno);
	}
	
	/**根据员工编号删除员工*/
	@Override
	public void delEmpByEmpno(String empno) {
		this.getSqlSession().delete("emp.delEmpByEmpno",empno);
	}
	
	public List<Emp> queryEmpList(Emp emp){
		List<Emp> empList = this.getSqlSession().selectList("emp.queryEmpList",emp);
		return empList;
	}
	
	public List<Emp> getEmpListByParam(Emp emp){
		List<Emp> empList = this.getSqlSession().selectList("emp.getEmpListByParam",emp);
		return empList;
	}
	
	public List<Emp> getEmpListByParamOrNoDeptRoleId(Emp emp){
		List<Emp> empList = this.getSqlSession().selectList("emp.getEmpListByParamOrNoDeptRoleId",emp);
		return empList;
	}
	/**
	 * 取得指定产品code对应部门的销售
	 */
	@Override
	public Emp getSpecialEmpByProductCode(String productCode) throws SQLException {
		return this.getSqlSession().selectOne("emp.getSpecialEmpByProductCode",productCode);
	}
	
	/**
	 * 修改员工剩余推送个数
	 */
	@Override
	public void updateSurplusLimit(Emp emp) throws SQLException {
		this.getSqlSession().update("emp.updateSurplusLimit",emp);
	}
}
